ImageGear Java PDF
Insert PDF Pages

To insert pages from one PDF document into another PDF document:

  1. Use the createDocument method of the PDF class to create two new instances of the Document class (one per PDF file).
  2. Use the openDocument method of the Document class to load the PDF documents.
  3. Use the insertPages methods of the Document class to insert pages of the first PDF document into the second PDF document.
  4. Use the saveDocument method of the Document class to save the resulting PDF document to a file.
  5. Use the close method of the Document class to close the documents if you do not need them anymore.

The following is an illustration of how to insert pages of one of the PDF document into another PDF document:

 
Copy Code
import com.accusoft.imagegearpdf.*;

class PdfDemo
{
        private PDF pdf;
        private Document destinationDocument;
        private Document sourceDocument;
        
        // Insert pages from source document into destination document.
        public void insertPages(long insertAtPageNumber, long startPageNumber, long pageCount)
        {
                try
                {
                        this.destinationDocument.insertPages(insertAtPageNumber, this.sourceDocument, startPageNumber, pageCount);
                }
                catch (Throwable ex)
                {
                        // Failed to insert pages into PDF document.
                        System.err.println("Exception: " + ex.toString());
                }
        }
}

See Also

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback